import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:banquanjie_app/app/services/screenAdapter.dart';
class VideoList extends StatelessWidget {
  final Map<String, dynamic> item;
  const VideoList({
    super.key,
    required this.item,
  });
  @override
  Widget build(BuildContext context) {
    return Container(
      width: ScreenAdapter.width(348),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(ScreenAdapter.width(8)),
      ),
      clipBehavior: Clip.antiAlias,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _buildCoverBox(),
          _buildInfoSection(),
        ],
      ),
    );
  }

  Widget _buildCoverBox() {
    return AspectRatio(
      aspectRatio: 1.96,
      child: SizedBox(
        width: ScreenAdapter.width(348),
        // height: ScreenAdapter.height(192),
        child: Stack(
          children: [
            // Overlay background
            Container(
              decoration: BoxDecoration(
                image: DecorationImage(
                  image: NetworkImage(
                    'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/video_cover_bg.png',
                  ),
                  fit: BoxFit.cover,
                ),
              ),
              child: CachedNetworkImage(
                imageUrl: item['coverOssUrl'] != null && item['coverOssUrl'].isNotEmpty ? item['coverOssUrl'] : 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/video_empty.png',
                width: double.infinity,
                height: double.infinity,
                fit: BoxFit.cover,
              )
            ),
            
            // Top icon
            if (item['topFlag'] == 1)
              Positioned(
                left: 0,
                top: 0,
                child: Image.network(
                  'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/top_icon.png',
                  width: ScreenAdapter.width(48),
                  height: ScreenAdapter.width(48),
                ),
              ),
            
            // Options (top-right)
            Positioned(
              top: ScreenAdapter.height(12),
              right: ScreenAdapter.width(12),
              child: Row(
                children: [
                  if (item['userEntrustFlag'] == 1)
                    Container(
                      width: ScreenAdapter.width(42),
                      height: ScreenAdapter.height(28),
                      margin: EdgeInsets.only(right: ScreenAdapter.width(6)),
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(ScreenAdapter.width(4)),
                      ),
                      alignment: Alignment.center,
                      child: Text(
                        '自营',
                        style: TextStyle(
                          fontSize: ScreenAdapter.fontSize(20),
                          color: const Color(0xFF666666),
                        ),
                      ),
                    ),
                    SizedBox(width: ScreenAdapter.width(4)),
                  if (item['copyrightChainFlag'] == 1)
                    Image.network(
                      'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/video_copy_icon.png',
                      width: ScreenAdapter.width(28),
                      height: ScreenAdapter.height(28),
                      // margin: const EdgeInsets.only(right: 5),
                    ),
                    SizedBox(width: ScreenAdapter.width(6)),
                  
                  if (item['worksProgressName'] != null && item['worksProgressName'].isNotEmpty)
                    Container(
                      width: ScreenAdapter.width(42),
                      height: ScreenAdapter.width(28),
                      decoration: BoxDecoration(
                        color: (item['worksProgress'] == 1778)
                            ? const Color(0xFF169BD5)
                            : Colors.white,
                        borderRadius: BorderRadius.circular(4),
                      ),
                      alignment: Alignment.center,
                      child: Text(
                        item['worksProgressName'].substring(0, item['worksProgressName'].length - 2),
                        style: TextStyle(
                          height: 1,
                          fontSize: ScreenAdapter.fontSize(20),
                          color: (item['worksProgress'] == 1778)
                              ? Colors.white
                              : const Color(0xFF666666),
                        ),
                      ),
                    ),
                ],
              ),
            ),
            
            // Count (bottom-left)
            Positioned(
              left: 0,
              bottom: 0,
              child: SizedBox(
                height: ScreenAdapter.width(34),
                child: Row(
                  children: [
                    Padding(
                      padding: EdgeInsets.fromLTRB(ScreenAdapter.width(12), 0, ScreenAdapter.width(6), 0),
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Image.network(
                            'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/see_count_icon.png',
                            width: ScreenAdapter.width(14),
                            height: ScreenAdapter.width(14),
                          ),
                          SizedBox(width: ScreenAdapter.width(12)),
                          Text(
                            item['viewNum']?.toString() ?? '0',
                            style: TextStyle(
                              fontSize: ScreenAdapter.fontSize(20),
                              color: Color(0xFFFAFAFA)
                            ),
                          ),
                        ],
                      ),
                    ),
                    Padding(
                      padding: EdgeInsets.fromLTRB(ScreenAdapter.width(12), 0, ScreenAdapter.width(6), 0),
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Image.network(
                            'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/collect_icon.png',
                            width: ScreenAdapter.width(14),
                            height: ScreenAdapter.width(14),
                          ),
                          SizedBox(width: ScreenAdapter.width(12)),
                          Text(
                            item['collectNum']?.toString() ?? '0',
                            style: TextStyle(
                              fontSize: ScreenAdapter.fontSize(20),
                              color: Color(0xFFFAFAFA),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      )
    );
  }

  Widget _buildInfoSection() {
    return Padding(
      padding: EdgeInsets.only(left: ScreenAdapter.width(12), right: ScreenAdapter.width(20), top: ScreenAdapter.width(10), bottom: ScreenAdapter.width(8)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // Type and title row
          SizedBox(
            height: ScreenAdapter.width(46),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                if (item['worksTypeFirstName'] != null)
                  Container(
                    margin: EdgeInsets.only(right: ScreenAdapter.width(14)),
                    height: ScreenAdapter.width(24),
                    constraints: BoxConstraints(minWidth: ScreenAdapter.width(52)),
                    padding: EdgeInsets.symmetric(horizontal: ScreenAdapter.width((6))),
                    decoration: BoxDecoration(
                      color: const Color(0xFFF0F2F5),
                      borderRadius: BorderRadius.circular(ScreenAdapter.width(4)),
                    ),
                    alignment: Alignment.center,
                    child: Text(
                      item['worksTypeFirstName'],
                      style: TextStyle(
                        fontSize: ScreenAdapter.fontSize(22),
                        height: 1.0,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  ),
                Expanded(
                  child: Text(
                    item['worksTitle'] ?? '',
                    style: TextStyle(
                      fontSize: ScreenAdapter.fontSize(28),
                      fontWeight: FontWeight.w600,
                    ),
                    overflow: TextOverflow.ellipsis,
                    maxLines: 1,
                  ),
                ),
              ],
            ),
          ),
          SizedBox(
            height: ScreenAdapter.width(40),
            child:  Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                if (item['worksTypeSecondName'] != null)
                  Text(
                    (item['worksTypeSecondName'] as String).replaceAll('|', ' / '),
                    style: TextStyle(
                      fontSize: ScreenAdapter.fontSize(24),
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                if (item['worksTradeFlag'] == 0)
                  Text(
                    '仅展示',
                    style: TextStyle(
                      fontSize: ScreenAdapter.fontSize(20),
                      color: Color(0xFF00B277),
                    ),
                  ),
              ],
            ),
          )
          // Second row with type and "only show" text
         
        ],
      ),
    );
  }
}